<?php
########################################################
# DMS Donations Management System v1.0                 #
# created by:  Isaac Sabas                             #
#			   Nikko Reyes							   #
#			   Miko Tiamwatt						   #
#                                                      #
# De La Salle Philippines                              #
# All Rights Reserved DLSP Copyright 2009              #
########################################################

define('ACCESS', true);	

session_start();	
	
# set error checking levels #	
	# enable these lines when site is to be deployed #	
	ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 'On');
    //ini_set('log_errors', 'On');
    //ini_set('error_log', '/usr/local/apache/logs/error_log');
	
	#############################
	# include some needed files #
	#############################
		$absRoot = '../../';
		include($absRoot . 'lib/XAJAX/xajax_core/xajax.inc.php');
		include($absRoot . 'src/ClientHandle.php');

	$id = $_GET["client_id"];

	$xajax = new xajax();

	$xajax->registerFunction("addClientAddress");

	
		function addClientAddress($type, $priority, $street, $municipality, $city, $province, $country, $zipcode, $id) {
		$statusresponse = new xajaxResponse();
	
		# check if the fields are empty
			if (empty($priority) || empty($type) || empty($street) || empty($municipality) || empty($city) || empty($province) || empty($country) || empty($zipcode)) {
				$statusresponse->assign('Status','style.color','red');
				$statusresponse->assign('Status', 'innerHTML', 'Please complete all fields.<br /> Not updating..');
			}
			else {
			
			/*'{$valuesArray['address_street']}',
							'{$valuesArray['address_city']}',
							'{$valuesArray['address_municipality']}',
							'{$valuesArray['address_province']}',
							'{$valuesArray['address_country']}',
							'{$valuesArray['address_zipcode']}',
							'{$valuesArray['address_type']}',
							'{$clientId}'*/

			if ($id != '') {
								
			$client = new ClientHandle();
			
			$Address['address_street']=$street;
			$Address['address_city']=$city;
			$Address['address_municipality']=$municipality;
			$Address['address_province']=$province;
			$Address['address_country']=$country;
			$Address['address_zipcode']=$zipcode;
			$Address['address_type']=$type;
			$Address['address_priority']=$priority;
			
			$result=$client->addNewAddress($Address,$id);	
						
						if($result 	== true)
						{
							//$statusresponse->call("parent.window.frames['view_client_profile_".$id."'].location.reload()");
							$statusresponse->call("parent.refresh_client_window($id)");
							$statusresponse->assign('Status','style.color','green');
							$statusresponse->assign('Status', 'innerHTML', 'Client Address added.<br /> Database updated.');
						}
						else
						{
							$statusresponse->assign('Status','style.color','red');
							$statusresponse->assign('Status', 'innerHTML', 'Database error.<br />Not updating..');
						}
					}
			
			}
			
								
		return$statusresponse;
	}
	
	$xajax->processRequest();		
	
# instantiate predifined classes #											

	//print_r($result);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
   	<meta http-equiv="content-type" content="text/html; charset=utf-8">
   	<title>{PAGE_TITLE}</title>	
   	<style type="text/css">
		/*margin and padding on body element
		  can introduce errors in determining
		  element position and are not recommended;
		  we turn them off as a foundation for YUI
		  CSS treatments. */
		body {
			margin:0;
			padding:0;
		}
	</style>		       	
	
	<!-- fonts -->
		<link rel="stylesheet" type="text/css" href="../../lib/YUI/yui/build/fonts/fonts-min.css" />
	<!-- fonts -->
	
	<!-- DMS style sheet -->				
			<link rel="stylesheet" type="text/css" href="../../css/dms.css" />
	<!-- DMS style sheet -->

	<script type="text/javascript" src="../../lib/XAJAX/xajax_js/xajax_core.js" />
	<?php $xajax->printJavaScript(); ?>	
</head>
<body class="yui-skin-sam">											
										

<form id="EditClientAddresses" action="#" method='post'>
<table>
	<tr>
	<td>
	Address Type:</td>
	<td>
			<select id="Type" name="Type">
			<option id="Primary" value="Residence">Residence</option>
			<option id="Secondary" value="Office">Office</option>
		</select>
	</td>
	</tr>
	<tr>
	<td>
	Address Priority:</td>
	<td>
			<select id="Priority" name="Priority">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
			<option value="4">4</option>
		</select>
	</td>
	</tr>
	<tr>
	<td>
	Street:</td>
	<td>
		<input type=text id="Street" name="Street"></input>
	</td>
	</tr>
	<tr>
	<td>
	Municipality:</td>
	<td>
		<input type=text id="Municipality"></input>
	</td>
	</tr>
	<tr>
	<td>
	City:</td>
	<td>
	<input type=text id="City"></input>
	</td>
	</tr>
	<tr>
	<td>
	Province:</td>
	<td>
	<input type=text id="Province"></input>
	</td>
	</tr>
	<tr>
	<td>
	Country:</td>
	<td>
	<input type=text id="Country"></input>
	</td>
	</tr>
	<tr>
	<td>
	Zip Code:</td>
	<td>
	<input type=text id="ZipCode"></input>
	</td>
	</tr>
	<tr>
	<td>
	</td>
	</tr>
	<tr>
	<td>
	</td>
	</tr>
	<tr>
	<td>
	</td>
	<td>
	<input type=button id="Update" value="Update" onClick="xajax_addClientAddress(document.getElementById('Type').value,document.getElementById('Priority').value,document.getElementById('Street').value, document.getElementById('Municipality').value,document.getElementById('City').value,document.getElementById('Province').value, document.getElementById('Country').value,document.getElementById('ZipCode').value, <?php echo $id;?>);"></input>
	<input type=reset id="Reset" value="Reset"></input>
	</td>
	</tr>
	
</table>
</form>

<div id='Status'></div>

</body>

</html>
